//
//  SMHProductSuggestView.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/6/3.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit
import ReactiveCocoa
class SMHProductSuggestView: LZBaseView {

    var viewModel = SMHProductViewModel()
    override init(viewModel: LZBaseViewModel) {
        super.init(viewModel: viewModel)
        self.viewModel = viewModel as! SMHProductViewModel
        setupUI()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: setupUI
    func setupUI()  {
        
        let contentH = 145
        self.frame = CGRect(x: 0, y: Int(kScreenHeight), width: Int(kScreenWidth), height: contentH)
        self.backgroundColor = UIColor.black.withAlphaComponent(0.5)
        let titleLab = UILabel()
        titleLab.text = "联系供货商"
        titleLab.textColor = UIColor.white
        titleLab.font = ktextBoldFont(size: 18)
        self.addSubview(titleLab)
        titleLab.snp.makeConstraints { (make) in
            make.left.equalTo(30)
            make.width.equalTo(245)
            make.height.equalTo(18)
            make.top.equalTo(15)
        }
        
        let details :[String] = ["姓名:","电话:","邮箱:"]
        for (index,item) in details.enumerated(){
            
            let detailLab = UILabel()
            detailLab.text = item
            detailLab.font = ktextFont(size: 14)
            detailLab.textColor = UIColor.white
            self.addSubview(detailLab)
            detailLab.snp.makeConstraints { (make) in
                make.left.equalTo(30)
                make.width.equalTo(245)
                make.height.equalTo(15)
                make.top.equalTo(titleLab.snp.bottom).offset(15 + index * (30))
            }
        }
        
        
        //!!!!:取消
        let cancelBtn = UIButton()
        cancelBtn.setImage(UIImage.init(named: "icon_product_cancel"), for: .normal)
        self.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.width.equalTo(25)
            make.height.equalTo(15)
            make.top.equalTo(10)
        }
        
        cancelBtn.reactive.controlEvents(.touchUpInside).observeValues { (button) in
            self.hidden()
        }
        
        
//           UIButton *cancelBtn = [UIButton lz_buttonImageName:@"icon_product_cancel" backgroundImageName:@""];
//           [self addSubview:cancelBtn];
//           [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//              make.height.mas_equalTo(25);
//              make.right.mas_equalTo(-15);
//              make.width.mas_equalTo(25);
//              make.top.mas_equalTo(10);
//           }];
        
    }

    
    //MARK:展示View
    func show()  {
            
        UIView.animate(withDuration: 0.25) {
            self.frame = CGRect(x: 0, y: kScreenHeight - CGFloat(self.height) - CGFloat(kBarHeight) - CGFloat(kNavHeight), width: kScreenWidth, height: CGFloat(self.height))
        }
        
    }
    
    //MARK:隐藏View
     func hidden()  {
           
        UIView.animate(withDuration: 0.24) {
            self.frame = CGRect(x: 0, y: Int(kScreenHeight), width: Int(kScreenWidth), height: Int(self.height))
        }
        
     }
}
